package com.my.chapter10;

public class practice17 {
    public static void playGame(GameFactory factory){
        Game s = factory.getGame();
        s.move();
    }

    public static void main(String[] args) {
        playGame(Coin.factory);
        playGame(Dice.factory);
    }
}

interface Game{
    void move();
}

interface GameFactory{
    Game getGame();
}

class Coin implements Game {
    private Coin(){}

    @Override
    public void move() {
        System.out.println("抛硬币");
    }

    public static GameFactory factory = new GameFactory() {
        @Override
        public Game getGame() {
            return new Coin();
        }
    };
}

class Dice implements Game {
    private Dice(){}

    @Override
    public void move() {
        System.out.println("掷骰子");
    }

    public static GameFactory factory = new GameFactory() {
        @Override
        public Game getGame() {
            return new Dice();
        }
    };
}
